const fs = require('fs');
const path = require('path');

// 确保目标目录存在
const ensureDirectoryExists = (dirPath) => {
  if (!fs.existsSync(dirPath)) {
    fs.mkdirSync(dirPath, { recursive: true });
  }
};

// 复制HTML文件
const copyHtmlFile = () => {
  const sourcePath = path.join(__dirname, '../src/renderer/index.html');
  const destPath = path.join(__dirname, '../dist/renderer/index.html');
  
  // 确保目标目录存在
  ensureDirectoryExists(path.dirname(destPath));
  
  try {
    // 读取源文件
    const content = fs.readFileSync(sourcePath, 'utf8');
    
    // 写入目标文件
    fs.writeFileSync(destPath, content, 'utf8');
    
    console.log('HTML文件复制成功:', destPath);
    return true;
  } catch (error) {
    console.error('HTML文件复制失败:', error.message);
    return false;
  }
};

// 执行复制
if (copyHtmlFile()) {
  process.exit(0);
} else {
  process.exit(1);
}